﻿<UserControl x:Class="Adaptive.ReactiveTrader.Client.UI.SpotTiles.SpotTilePricingView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:spotTiles="clr-namespace:Adaptive.ReactiveTrader.Client.UI.SpotTiles;assembly=Adaptive.ReactiveTrader.Client"
             xmlns:designer="clr-namespace:Adaptive.ReactiveTrader.Client.UI.SpotTiles.Designer;assembly=Adaptive.ReactiveTrader.Client"
             mc:Ignorable="d" 
             d:DesignHeight="150"
             d:DesignWidth="328"
             d:DataContext="{d:DesignInstance designer:DesignTimeSpotTilePricingViewModel, IsDesignTimeCreatable=True}">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Adaptive.ReactiveTrader.Client.GUI;component/Styles/Brushes.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <SolidColorBrush x:Key="MouseOverBrush">#FF2F5078</SolidColorBrush>

            <DataTemplate x:Key="PriceDataTemplate" DataType="spotTiles:IOneWayPriceViewModel">
                <Button Command="{Binding ExecuteCommand}" Cursor="Hand">
                    <Button.Style>
                        <Style TargetType="Button">
                            <Setter Property="Background" Value="Transparent" />
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="Button">
                                        <Border Background="{TemplateBinding Background}">
                                            <ContentPresenter Content="{TemplateBinding Content}" />
                                        </Border>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                            <Style.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Background" Value="{StaticResource MouseOverBrush}" />
                                </Trigger>
                                <Trigger Property="IsPressed" Value="True">
                                    <Setter Property="Background" Value="#FF345C8B" />
                                </Trigger>
                                <DataTrigger Binding="{Binding IsExecuting}" Value="True">
                                    <Setter Property="Background" Value="{StaticResource MouseOverBrush}" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Button.Style>

                    <UserControl>
                        <UserControl.Template>
                            <ControlTemplate TargetType="UserControl">
                                <StackPanel Margin="0,5,0,0">
                                    <TextBlock Text="{Binding Direction}" HorizontalAlignment="Center" FontSize="16" Foreground="{StaticResource SecondaryForeground}" />
                                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,-8,0,0">
                                        <TextBlock Text="{Binding BigFigures}" FontSize="18" Foreground="{StaticResource SecondaryForeground}" Style="{StaticResource {x:Type TextBlock}}" />
                                        <TextBlock x:Name="PipsText" Text="{Binding Pips}" FontSize="48" FontWeight="Light" Foreground="{StaticResource PrimaryForeground}" Margin="5,0" />
                                        <TextBlock x:Name="TenthOfPipText" Text="{Binding TenthOfPip}" FontSize="18" Foreground="{StaticResource SecondaryForeground}" Style="{StaticResource {x:Type TextBlock}}" />
                                    </StackPanel>
                                </StackPanel>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsEnabled" Value="False">
                                        <Setter TargetName="PipsText" Property="Foreground" Value="{StaticResource SecondaryForeground}" />
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </UserControl.Template>
                    </UserControl>
                </Button>
            </DataTemplate>
        </ResourceDictionary>
    </UserControl.Resources>
    <UserControl.Template>
        <ControlTemplate TargetType="UserControl">
            <Border x:Name="RootBorder" Padding="15,12" Background="{StaticResource TileBackgroundBrush}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <DockPanel Grid.Row="0" LastChildFill="False">
                        <TextBlock DockPanel.Dock="Left" 
                            Text="{Binding Symbol, Mode=OneWay}" 
                            Foreground="{StaticResource PrimaryForeground}" FontSize="18" />

                        <TextBlock x:Name="ExecutingStatusTextBlock" DockPanel.Dock="Right" Visibility="Collapsed"
                            Text="EXECUTING" 
                            Foreground="{StaticResource PrimaryForeground}" FontSize="18" />
                    </DockPanel>

                    <Grid x:Name="PriceButtonsPanel" Grid.Row="1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <ContentControl x:Name="BidContentControl" Grid.Column="0" 
                            Margin="0,0,5,0"
                            Content="{Binding Bid}" 
                            ContentTemplate="{StaticResource PriceDataTemplate}"/>

                        <StackPanel Grid.Column="1" VerticalAlignment="Center">
                            <Path x:Name="UpMovementIcon" Data="M6,0L12,12 0,12z" Fill="#FF3FCF1E" Height="12" Width="12" Visibility="Hidden" />
                            <TextBlock x:Name="SpreadTextBlock"  Text="{Binding Spread}" FontSize="16" Foreground="{StaticResource PrimaryForeground}" Margin="3,5" />
                            <Path x:Name="DownMovementIcon" Data="M6,12L0,0 12,0z" Fill="#FFCC3350" Height="12" Width="12" Visibility="Hidden" />
                        </StackPanel>

                        <ContentControl x:Name="AskContentControl" Grid.Column="2" 
                            Margin="5,0,0,0"
                            Content="{Binding Ask}" 
                            ContentTemplate="{StaticResource PriceDataTemplate}"/>
                    </Grid>

                    <TextBlock x:Name="StaleTextBlock" Grid.Row="1" Visibility="Collapsed" VerticalAlignment="Top"
                            Text="Pricing currently unavailable" 
                            Foreground="{StaticResource PrimaryForeground}" FontSize="16" />

                    <TextBlock x:Name="SubscribingTextBlock" Grid.Row="1" Visibility="Collapsed" VerticalAlignment="Top"
                            Text="Subscribing..." 
                            Foreground="{StaticResource SecondaryForeground}" FontSize="16" />

                    <DockPanel x:Name="NotionalPanel" Grid.Row="2">
                        <TextBlock x:Name="SpotDateTextBlock" DockPanel.Dock="Right" Text="{Binding SpotDate}" Foreground="{StaticResource SecondaryForeground}" FontSize="16" Visibility="Collapsed" />

                        <UserControl>
                            <UserControl.Template>
                                <ControlTemplate TargetType="UserControl">
                                    <Border x:Name="Border" BorderThickness="0,0,0,1" HorizontalAlignment="Left" Width="146">
                                        <DockPanel>
                                            <TextBlock x:Name="DealtCcyTextBlock" DockPanel.Dock="Left" Text="{Binding DealtCurrency}" Foreground="{StaticResource SecondaryForeground}" FontSize="16" />

                                            <TextBox x:Name="NotionalTextBox" Text="{Binding Notional, Mode=TwoWay}" 
                                                TextAlignment="Left"
                                                VerticalContentAlignment="Center" Margin="5,0"
                                                FontSize="16"
                                                Background="Black" 
                                                Foreground="{StaticResource SecondaryForeground}">
                                                <TextBox.Template>
                                                    <ControlTemplate TargetType="TextBox">
                                                        <ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
                                                    </ControlTemplate>
                                                </TextBox.Template>
                                            </TextBox>
                                        </DockPanel>
                                    </Border>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsMouseOver" Value="True">
                                            <Setter TargetName="Border" Property="Background" Value="{StaticResource MouseOverBrush}" />
                                            <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource PrimaryForeground}" />
                                            <Setter TargetName="DealtCcyTextBlock" Property="Foreground" Value="{StaticResource PrimaryForeground}" />
                                            <Setter TargetName="NotionalTextBox" Property="Foreground" Value="{StaticResource PrimaryForeground}" />
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </UserControl.Template>
                        </UserControl>
                       
                    </DockPanel>
                </Grid>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter TargetName="RootBorder" Property="Background" Value="#FF294464" />
                    <Setter TargetName="SpotDateTextBlock" Property="Visibility" Value="Visible" />
                </Trigger>
                <DataTrigger Binding="{Binding Bid.IsExecuting}" Value="True">
                    <Setter TargetName="SpreadTextBlock" Property="Foreground" Value="{StaticResource SecondaryForeground}" />
                    <Setter TargetName="ExecutingStatusTextBlock" Property="Visibility" Value="Visible" />
                    <Setter TargetName="BidContentControl" Property="IsEnabled" Value="False" />
                    <Setter TargetName="AskContentControl" Property="IsEnabled" Value="False" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Ask.IsExecuting}" Value="True">
                    <Setter TargetName="SpreadTextBlock" Property="Foreground" Value="{StaticResource SecondaryForeground}" />
                    <Setter TargetName="ExecutingStatusTextBlock" Property="Visibility" Value="Visible" />
                    <Setter TargetName="BidContentControl" Property="IsEnabled" Value="False" />
                    <Setter TargetName="AskContentControl" Property="IsEnabled" Value="False" />
                </DataTrigger>
                <DataTrigger Binding="{Binding IsStale}" Value="True">
                    <Setter TargetName="PriceButtonsPanel" Property="Visibility" Value="Hidden" />
                    <Setter TargetName="NotionalPanel" Property="Visibility" Value="Hidden" />
                    <Setter TargetName="StaleTextBlock" Property="Visibility" Value="Visible" />
                    <Setter TargetName="RootBorder" Property="Background" Value="{StaticResource ErrorBackgroundBrush}" />
                </DataTrigger>
                <DataTrigger Binding="{Binding IsSubscribing}" Value="True">
                    <Setter TargetName="PriceButtonsPanel" Property="Visibility" Value="Hidden" />
                    <Setter TargetName="NotionalPanel" Property="Visibility" Value="Hidden" />
                    <Setter TargetName="SubscribingTextBlock" Property="Visibility" Value="Visible" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Movement}" Value="{x:Static spotTiles:PriceMovement.Up}">
                    <Setter TargetName="UpMovementIcon" Property="Visibility" Value="Visible" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Movement}" Value="{x:Static spotTiles:PriceMovement.Down}">
                    <Setter TargetName="DownMovementIcon" Property="Visibility" Value="Visible" />
                </DataTrigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </UserControl.Template>
</UserControl>
